<template>
  <div class="header">
    <div class="header-left">
     中部地区
    </div>
    <div class="header-right">
      <!-- vant的搜索框 -->
      <van-search 
      v-model="searchValue"
      shape="round"
      placeholder="请输入搜索关键词"
       @search="onSearch"
       />
    </div>
  </div>
  <div>
    <van-swipe class="my-swiper" :autoplay="3000" lazy-render>
      <van-swipe-item v-for="image in homeData.slides" :key="image.id">
    <van-image :src="image.pic_image_url" radius="10px" />
  </van-swipe-item>
</van-swipe>
<van-row justify="space-around">
  <van-col span = "11" v-for="(item, index) in homeData.nav2s"  :key="item.id" @click="goTo(index)">
    <van-image :src="item.pic_image_url" radius="10px" />
  </van-col>
</van-row>
<van-row @click="getOrder(item)" class="yy-list" v-for="item in homeData.hospitals" :key="item.id" justify="space-around">
  <van-col span="6">
    <van-image :src="item.avatar_url" width="100" height="90"></van-image>
  </van-col>
  <van-col class="yy" span="15">
    <div class="yy-name">{{ item.name }}</div>
    <div class="yy-type">
      <span>{{ item.rank }}</span>&nbsp;
      <span>{{ item.label }}</span>
    </div>
    <div class="yy-text">{{ item.intro }}</div>
  </van-col>
</van-row>
 
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import {useRouter} from 'vue-router'
import {getIndexListApi} from '../../api'

const router = useRouter()
//首页数据
const homeData = ref(
  {
    hospitals: [],
    nav2s: [],
    navs: [],
    now: '',
    slides: [],
  }
)
const searchValue = ref('')
const getIndexList = async() => {
  const res = await getIndexListApi()
  homeData.value = res.data.data
  console.log(homeData.value, 'home中的数据')
  // console.log(res, 'home中的数据')
}
onMounted(() => {
  getIndexList()
})

const goTo = (index) => {
  console.log(index)
  console.log(typeof(index))
  //由于数据类型是ref类型，所以要加上.value
  router.push(`/createOrder?id=${homeData.value.hospitals[index].id}`)
}
const getOrder = (data) => {
  console.log(data)
  router.push(`/createOrder?id=${data.id}`)
}


</script>

<style scoped lang="less">
//实现中部地区中间和右边的搜索框中间水平对齐
.header {
    display: flex;
    justify-content: space-between;
    margin: 5px;
    line-height: 54px;
    .header-left {
      padding-left: 22px;
      background: url()
        no-repeat left center;
      background-size: 20px;
      font-size: 20px;
      font-weight: bold;
      color: #666666;
    }
  }
  .my-swiper {
    margin: 5px;
  }
  .yy-list {
    padding-bottom: 10px;
    margin: 20px 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
    .yy {
      .yy-name {
        font-size: 20px;
        line-height: 30px;
        font-weight: bold;
      }
      .yy-type {
        font-weight: bold;
        line-height: 25px;
        font-size: 15px;
        color: #0ca7ae;
      }
      .yy-text {
        font-size: 14px;
        color: #999999;
      }
    }
  }
  .bottom-text {
    line-height: 50px;
    text-align: center;
    color: #999999;
  }

</style>